<div class="clearfix mb1x">
  <span class="pull-left">
    <?php echo L('available_balance');?>:
    <strong class="text-bold js-balance" style="margin-left:5px;"><?php echo currency($user['user_money']);?></strong>
  </span>
  <a href="<?php echo url('user/account_detail')?>" class="pull-right btn btn-middle"><?php echo L('consumer_details');?></a>
</div>
<table class="table-list">
  <tr>
    <th width="20%"><?php echo L('recharge_time')?></th>
    <th width="10%"><?php echo L('recharge_type')?></th>
    <th width="10%"><?php echo L('recharge_ampount')?></th>
    <th width="20%"><?php echo L('user_notes')?></th>
    <th width="20%"><?php echo L('admin_notes')?></th>
    <th width="10%"><?php echo L('recharge_status')?></th>
    <th width="10%"><?php echo L('operating')?></th>
  </tr>
  <?php
  if(isset($accountList) && $accountList):
  foreach ($accountList as $account) :
  ?>
  <tr>
    <td><?php echo date('Y-m-d H:i:s',$account['add_time']);?></td>
    <td><?php echo L(UserModel::$processType[$account['process_type']]);?></td>
    <td><?php echo currency($account['amount']);?></td>
    <td><?php echo $account['user_note'] ? $account['user_note'] : 'N/A';?></td>
    <td><?php if($account['admin_note'] == 'gift_card'){echo L('gift_card');}else if($account['admin_note'] == '_Fabric_Swatches_'){echo L('_Fabric_Swatches_');}else if($account['admin_note'] == 'register'){echo L('account_register');}else{echo $account['admin_note'] ? $account['admin_note'] : 'N/A';}?></td>
    <td><?php echo L(UserModel::$accountStatus[$account['is_paid']]);?></td>
    <td>
      <?php if($account['is_paid']==0){?>
        <a href="<?php echo url('user/account_cancel', array('acc_id' => $account['id']))?>"><?php echo L('cancel')?></a>
      <?php }?>
    </td>
  </tr>
  <?php
    endforeach;
    else:
  ?>
  <tr>
    <td colspan="7" class="no-record"><?php echo L('norecords')?></td>
  </tr>
  <?php endif;?>
</table>
<div class="mt1x mb1x align-right">
 <?php echo L('_account_balance_');?>: <strong class="text-bold js-balance" style="margin-left:5px;"><?php echo currency($user['user_money']);?></strong>
</div>
<div class="page"><?php echo $pageShow ?></div>
<div class="align-right recharge js-recharge">
  <em><?php echo L('gift_user_account_1');?></em>
  <input type="text" name="rechargeCode" class="text-bold">
  <button type="button" class="btn"><?php echo L('gift_user_account_2')?></button>
</div>
<script src="/statics/front/js/plugins/jquery.popupBox.js"></script>
<script>
$(function () {
  var $recharge = $('.js-recharge');

  $recharge.find('button').on('click', function(){
    var $this = $(this),
        $rechargeCode = $recharge.find('input[name=rechargeCode]'),
        empty = /^\s*$/;

    if ( empty.test($rechargeCode.val()) ) {
      $rechargeCode.addClass('error');
      return false;
    }

    $.ajax({
      url: "<?php echo U('/gift/recharge/code'); ?>" + "/" + $rechargeCode.val(),
      type: 'GET',
      dataType: 'json'
    }).done(function(response) {
      if (response.return_no === 0 && response.user_money === null) {
        $this.popupBox({
          eventType: null,
          quickClose: true,
          content: function() {
            return '<?php echo L('gift_user_account_validate_0')?>';
          },
          beforeShow: function (trigger, popupBox) {
            popupBox.addClass('align-center').css('width', 300);
          }
        });
      } else if (response.return_no === 1 && response.user_money !== null) {
        $this.popupBox({
          eventType: null,
          quickClose: true,
          content: function() {
            return '<?php echo L('gift_user_account_validate_1')?>';
          },
          beforeShow: function (trigger, popupBox) {
            popupBox.addClass('align-center').css('width', 300);
          }
        });
        $('.js-balance').text(response.user_money);
      } else if (response.return_no === 2 && response.user_money === null) {
        $this.popupBox({
          eventType: null,
          quickClose: true,
          content: function() {
            return '<?php echo L('gift_user_account_validate_2')?>';
          },
          beforeShow: function (trigger, popupBox) {
            popupBox.addClass('align-center').css('width', 300);
          }
        });
      }
    });
  });

  $recharge.find('input[name=rechargeCode]').on('focus', function () {
    $(this).removeClass('error');
  });
});
</script>